import { has } from "../../underscore"

export default function memoize(func, hasher?: Function) {
  var cache = {}
  var memoize = function (key) {
    var address = '' + (hasher ? hasher.apply(this, arguments) : key)
    if (!has(cache, address)) cache[address] = func.apply(this, arguments)
    return cache[address]
  }
  return memoize
}